package chpt06;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class StreamDemo {
	private static List<Apple> appleStore = new ArrayList<>();
	static {
		appleStore.add(new Apple(1, "red", 500, "湖南"));
		appleStore.add(new Apple(2, "red", 250, "烟台"));
		// appleStore.add(null);
		appleStore.add(new Apple(3, "green", 300, "湖南"));
		appleStore.add(new Apple(4, "green", 200, "天津"));
		appleStore.add(new Apple(5, "green", 100, "天津"));
	}

	public static void main(String[] args) {
		// 1.过滤颜色为“red”且重量大为300的Apple对象
		List<Apple> filterApples1 = new ArrayList<>();
		for (Apple apple : appleStore) {
			if ("red".equals(apple.getColor()) && apple.getWeight() > 300)
				filterApples1.add(apple);
		}
		System.out.println("颜色为red，重量大于300的Apple：" + filterApples1);

		// 2.过滤颜色为“red”，产地为“烟台”的Apple对象
		List<Apple> filterApples2 = appleStore.stream().filter(a -> "red".equals(a.getColor()))
				.filter(a -> "烟台".equals(a.getOrigin())).collect(Collectors.toList());
		System.out.println("颜色为red， 产地为烟台的Apple：" + filterApples2);
	}
}
